import AbsTopo from './abstopo.js'
import topoconduct from '../common/struct/basestruct/topoconduct.js';

//拓扑连通资源类
class Conduct extends AbsTopo.AbsTopo {
    constructor() {
        super();
        this.m_connNodeList = new Array();
        this.type = "conduct";
    }

    addNode(node) {
        if (node) {
            if (this.m_connNodeList.indexOf(node) == -1) {
                this.m_connNodeList.push(node);
            }
            node.setRefRes(this);
        }
    }


    removeNode(node) {
        if (node) {
            let count = this.m_connNodeList.length;
            for (let i = count - 1; i >= 0; i--) {
                if (this.m_connNodeList[i] == node) {
                    this.m_connNodeList.splice(i, 1);
                    break;
                }
            }
        }
    }

    getConnNodeList() {
        return this.m_connNodeList;
    }

    clearNodes(){
        this.m_connNodeList = [];
    }

    setUseful(v) { 
        this.m_useful = v;
        if (v == 0){
            this.m_connNodeList.forEach(node => {
                node.setUseful(0);
            });
        } 
    }

    toInfo() {
        let info = new topoconduct.TopoConduct();
        info.id = this.id;
        if (this.m_refGraph) {
            info.refID = this.m_refGraph.m_rid;
        }
        else {
            this.setUseful(0);
        }
        return info;
    }

    notifyPosChang(preCnt, curentCnt,mapscale,inMulSelRegionLineLst) {
        let count = this.m_connNodeList.length;
        for (let i = count - 1; i >= 0; i--) {
            let node = this.m_connNodeList[i];
            let x = node.x - preCnt.x;
            let y = node.y - preCnt.y;
            let offsetPt = {x,y};
            node.translate(curentCnt,offsetPt,inMulSelRegionLineLst);
        }
    }
}

export default { Conduct }